const useDictStore = defineStore(
  'dict',
  {
    state: () => ({
      dict: []
    }),
    actions: {
      // 获取字典
      getDict(_key) {
        if (!_key) {
          return null;
        }
        const found = this.dict.find(item => item.key === _key);
        return found ? found.value : null;
      },

      // 设置字典
      setDict(_key, value) {
        if (_key) {
          this.dict.push({
            key: _key,
            value: value
          });
        }
      },
      // 删除字典
      removeDict(_key) {
        const index = this.dict.findIndex(item => item.key === _key);
        if (index !== -1) {
          this.dict.splice(index, 1);
          return true;
        }
        return false;
      },
      // 清空字典
      cleanDict() {
        this.dict = [];
      },
      // 初始字典
      initDict() {
      }
    }
  })

export default useDictStore
